#include <stdio.h>
#include <stdlib.h>

#include "sqlite3.h"

#define SELECT "select * from studen;"
#define DBNAME "/tmp/mysql.db"

int main(void)
{
	printf("Content-Type:text/html\n\n");
	sqlite3 *ppdb;
	int ret = sqlite3_open(DBNAME, &ppdb);  //打开数据库
	if(ret != SQLITE_OK)
	{
		printf("open db error\n\n");
		return -1;
	}
	
	
	char **result = NULL;
	char *err     = NULL;
	int  row      = 0;
	int  col      = 0;
	char *sql     = SELECT;
	ret = sqlite3_get_table(ppdb, sql, &result, &row, &col, &err);
	if(ret != SQLITE_OK)
	{
		printf("%s\n\n",err);
		return ;
	}
	int i=0;
	int j=0;
	for(i=0; i<(row+1); i++)
	{
		for(j=0; j<col; j++)
		{
			printf("%s&nbsp;&nbsp;&nbsp;\n\n",result[i*col+j]);
		}
		printf("<br/>\n\n");
	}	
	sqlite3_free_table(result);
	
	sqlite3_close(ppdb);
	
	return 0;	
}
